import Page
from Page import Personal
from Base.Base import Base
from selenium.webdriver.common.by import By


class PersonalAuthorizeOpenTwoPage(Base):
    """
    个人中心授权认证步骤二
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.authorize_home_btn = (By.XPATH, Personal.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.authorize_back_btn = (By.XPATH, Personal.RESOURCE_ID.format('ivBack'))

        # 支付标题
        self.authorize_payment_title_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_pay_tip"))

        # 微信二维码文本
        self.authorize_wecharm_qr_code_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_wechat_code"))

        # 支付宝二维码文本
        self.authorize_alipay_qr_code_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_alipay_code"))

        # 支付二维码
        self.authorize_qr_code_icon = (By.XPATH, Personal.RESOURCE_ID.format("iv_qr_code"))

        # 刷新二维码
        self.authorize_refresh_btn = (By.XPATH, Personal.RESOURCE_ID.format("tv_complete_or_refresh"))

        # 失效图标
        self.authorize_failure_icon = (By.XPATH, Personal.RESOURCE_ID.format("iv_net_error"))

        # 失效二维码提示
        self.authorize_failure_tip_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_net_error_text"))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.authorize_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.authorize_back_btn)

    def get_payment_title(self):
        """
        获取支付标题

        :return:
        """
        return self.find_element_o(self.authorize_payment_title_text)

    def get_wecharm_qr_code(self):
        """
        获取微信二维码文本

        :return:
        """
        return self.find_element_o(self.authorize_wecharm_qr_code_text)

    def get_alipay_qr_code(self):
        """
        获取支付宝二维码文本

        :return:
        """
        return self.find_element_o(self.authorize_alipay_qr_code_text)

    def get_qr_code(self):
        """
        获取支付二维码

        :return:
        """
        return self.find_element_o(self.authorize_qr_code_icon)

    def get_failure(self):
        """
        获取失效图标

        :return:
        """
        return self.find_element_o(self.authorize_failure_icon)

    def get_failure_tip(self):
        """
        获取失效二维码

        :return:
        """
        return self.find_element_o(self.authorize_failure_tip_text)

    def click_refresh(self):
        """
        点击刷新按钮

        :return:
        """
        self.click_element(self.authorize_refresh_btn)

    def is_display_authorize_failure(self):
        """
        是否存在授权信息失效页

        :return: bool
        """
        return self.is_display(self.authorize_failure_tip_text)

    def is_display_authorize_step_two(self):
        """
        是否存在授权信息步骤二页

        :return: bool
        """
        return self.is_display(self.authorize_refresh_btn)
